package com.yueya.basic.role.model;

import java.util.List;

import com.jfinal.aop.Duang;
import com.jfinal.plugin.activerecord.Model;
import com.yueya.basic.role.service.RoleUserService;

@SuppressWarnings("serial")
public class RoleUser extends Model<RoleUser> {
	public static final RoleUser dao = new RoleUser();

	public static RoleUserService service = Duang.duang(RoleUserService.class);

	public List<RoleUser> getListByUserId(String user_id) {

		String sql = "select * from t_role_user where user_id = ?";
		List<RoleUser> li = RoleUser.dao.find(sql, user_id);

		return li;
	}

	/**
	 * 通过userid删除
	 * 
	 * @param user_id
	 */
	public void deleteByUserId(String user_id) {
		String sql = "select * from t_role_user where user_id = '" + user_id + "'";
		List<RoleUser> list = RoleUser.dao.find(sql);
		RoleUser r = null;
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				r = (RoleUser) list.get(i);
				r.delete();
			}
		}
	}

	/**
	 * 通过roleid删除
	 * 
	 * @param role_id
	 */
	public void deleteByRoleId(String role_id) {
		String sql = "select * from t_role_user where role_id = '" + role_id + "'";
		List<RoleUser> list = RoleUser.dao.find(sql);
		RoleUser r = null;
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				r = list.get(i);
				r.delete();
			}
		}
	}
}
